
public class Library {

	private Object[] holdings;
	private int count;

	public Library(int capacity) {
		if (capacity < 1) {
			throw new IllegalArgumentException("invalid library capacity");
		}
		holdings = new Object[capacity];
		count = 0;
	}

	public void add(Object holding) {
		if (!contains(holding)) {
			if (count < holdings.length) {
				holdings[count] = holding;
				++count;
			}
			else {
				throw new IllegalStateException("library is full");
			}
		}
	}

	public boolean contains(Object holding) {
		for (int i=0; i < count; ++i) {
			if (holdings[i].equals(holding)) {
				return true;
			}
		}
		return false;
	}

	public String toString() {
		String result = "Library:\n";
		
		for (int i=0; i < count; ++i) {
			result += ("\t" + holdings[i].toString() + "\n");
		}

		return result;
	}

	public static void main(String[] args) {
		Library library = new Library(10);

		Book book = new Book("QA 76.7", "War and Peace", 1000);
		Video video = new Video("ST 433.xyz 1987", "Pirates of Silicon Valley", 105);

		library.add(book);
		library.add(video);
		library.add(book);
		library.add(video);

		System.out.println(library.toString());
	}

}

